home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / www / src / midaswww-1.0 / SGMLAnchorText.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-16  |  6.5 KB  |  170 lines

  1. /*==================================================================*/
  2. /*                                                                  */
  3. /* SGMLAnchorTextObject                                             */
  4. /*                                                                  */
  5. /* T.Johnson - (TonyJ@Slacvx.Slac.Stanford.Edu)           June.92   */
  6. /*                                                                  */
  7. /* Defines a anchortext segment for the SGMLHyper widget            */
  8. /*                                                                  */
  9. /*==================================================================*/
  10.  
  11. #ifdef VAX
  12. #include ctype
  13. #endif
  14.  
  15. #include <X11/IntrinsicP.h>
  16. #include <X11/StringDefs.h>
  17. #include <X11/CoreP.h>
  18. #include "SGMLAnchorTextP.h"
  19. #include <string.h>
  20.  
  21. /* 
  22.   Private functions 
  23. */
  24.  
  25. /*
  26.   Widget class methods
  27. */
  28.  
  29. static void    Initialize();
  30. static void    Destroy();
  31.  
  32. #define Offset(field) XtOffsetOf(SGMLAnchorTextRec,sgml_anchortext.field)
  33.  
  34. static XtResource resources[] = {
  35.  
  36.  
  37.     {SGMLNhref, SGMLCHref, XtRString, sizeof(String),
  38.     Offset(href), XtRString, ""},
  39.  
  40.     {SGMLNname, SGMLCName, XtRString, sizeof(String),
  41.     Offset(name), XtRString, ""},
  42.  
  43.     {SGMLNhrefLength, SGMLCHrefLength, XtRInt, sizeof(int),
  44.     Offset(href_length), XtRImmediate, 0},
  45.  
  46.     {SGMLNnameLength, SGMLCNameLength, XtRInt, sizeof(int),
  47.     Offset(name_length), XtRImmediate, 0}
  48.  
  49. };
  50. #undef Offset
  51.  
  52. /*---------------------------------------------------------------*/
  53. /* Static initialisation of the class record                     */
  54. /*---------------------------------------------------------------*/
  55.  
  56. SGMLAnchorTextClassRec  sGMLAnchorTextClassRec = {
  57.     {
  58.     (WidgetClass) &sGMLFormattedTextClassRec,    /* superclass    */
  59.     "SGMLAnchorText",                    /* class_name            */
  60.     sizeof(SGMLAnchorTextRec),           /* widget_size           */
  61.     NULL,                                /* class_initialize      */
  62.     NULL,                                /* class_part_initialize */
  63.     FALSE,                               /* class_inited          */
  64.     Initialize,                          /* initialize            */
  65.     NULL,                                /* initialize_hook       */
  66.     NULL,                                /* obj1                  */
  67.     NULL,                                /* obj2                  */
  68.     0,                                   /* obj3                  */
  69.     resources,                           /* resources             */
  70.     XtNumber(resources),                 /* num_resources         */
  71.     NULLQUARK,                           /* xrm_class             */
  72.     0,                                   /* obj4                  */
  73.     0,                                   /* obj5                  */
  74.     0,                                   /* obj6                  */
  75.     0,                                   /* obj7                  */
  76.     Destroy,                             /* destroy               */
  77.     NULL,                                /* obj8                  */
  78.     NULL,                                /* obj9                  */
  79.     NULL,                                /* set_values            */
  80.     NULL,                                /* set_values_hook       */
  81.     NULL,                                /* obj10                 */
  82.     NULL,                                /* get_values_hook       */
  83.     NULL,                                /* obj11                 */
  84.     XtVersion,                           /* version               */
  85.     NULL,                                /* callback private      */
  86.     NULL,                                /* obj12                 */
  87.     NULL,                                /* obj13                 */
  88.     NULL,                                /* obj14                 */
  89.     NULL,                                /* extension             */
  90.     },
  91.     {
  92.     SGMLInheritComputeSize,              /* compute_size          */
  93.     SGMLInheritAdjustSize,               /* adjust_size           */
  94.     SGMLInheritAdjustPosition,        /* adjust_position       */
  95.     SGMLInheritExpose,                   /* expose                */
  96.     SGMLInheritActivate,                 /* activate              */
  97.     SGMLInheritHilite,                   /* hilite                */
  98.     SGMLInheritContains,                 /* contains              */
  99.     SGMLInheritCallCreateCallback,       /* call_create_callback  */
  100.     SGMLInheritCallMapCallback,          /* call_map_callback     */
  101.     SGMLInheritMakeVisible,              /* make_visible          */
  102.     NULL,                                /* extension             */
  103.     }
  104. };
  105.  
  106. WidgetClass sGMLAnchorTextObjectClass = (WidgetClass) &sGMLAnchorTextClassRec;
  107.  
  108. /*--------------------------------------------------------------*/
  109. /* Initialize:                                                  */
  110. /*--------------------------------------------------------------*/
  111.  
  112. static void Initialize (request, new)
  113. SGMLAnchorTextObject request, new;
  114. {
  115.    char *key1 = "href=";
  116.    char *key2 = "name=";
  117.    char *delim = " \n\t";
  118.    char *p, *q; 
  119.    int l;
  120.  
  121.    q = XtNewString(new->sgml_text.param);
  122.    for (p = q ; *p != '\0' ; p++) if (isupper(*p)) *p = tolower(*p);
  123.  
  124.    p = strstr(q,key1);
  125.    if (p)
  126.      {
  127.        p += strlen(key1);
  128.        new->sgml_anchortext.href_length = l = strcspn(p,delim);
  129.        new->sgml_anchortext.href = strncpy((char *)XtMalloc(l+1),new->sgml_text.param+(p-q),l);
  130.        *(new->sgml_anchortext.href + l) = '\0';
  131.      }
  132.    else new->sgml_anchortext.href = XtNewString("");  
  133.  
  134.    p = strstr(q,key2);
  135.    if (p)
  136.      {
  137.        p += strlen(key2);
  138.        new->sgml_anchortext.name_length = l = strcspn(p,delim);
  139.        new->sgml_anchortext.name = strncpy((char *)XtMalloc(l+1),new->sgml_text.param+(p-q),l);
  140.        *(new->sgml_anchortext.name + l) = '\0';
  141.      }   
  142.    else new->sgml_anchortext.name = XtNewString("");
  143.    
  144.    XtFree(q);
  145. }
  146.  
  147. /*--------------------------------------------------------------*/
  148. /* Destroy the widget: release all memory allocated             */
  149. /*--------------------------------------------------------------*/
  150.  
  151. static void Destroy (w)
  152. SGMLAnchorTextObject w;
  153. {
  154.    XtFree(w->sgml_anchortext.href);
  155.    XtFree(w->sgml_anchortext.name);
  156. }
  157.  
  158. /*-----------------------------------------------------------------------*/
  159. /* Create a new SGMLAnchorTextObject                                           */
  160. /*-----------------------------------------------------------------------*/
  161.  
  162. Widget SGMLCreateAnchorText(parent,name,al,ac)
  163. Widget parent;
  164. char   *name;
  165. ArgList al;
  166. int     ac;
  167. {
  168.     return XtCreateWidget(name,sGMLAnchorTextObjectClass,parent,al,ac);
  169. }
  170.